/**
 * 
 */
package cn.edu.tyu.finance.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import cn.edu.tyu.finance.entity.dao.UserDaoImpl;
import cn.edu.tyu.finance.entity.domain.Users;




/**
 * MySQL数据库的实用类
 * @author YueJiang
 * @version 1.0
 */
public class DbUtil {
	/* 归还数据库的连接 */
	 	public static void backConn(Connection conn,PreparedStatement ps,ResultSet rs) {
		if(rs!=null) {
			try {
				rs.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		if(ps!=null) {
			try {
				ps.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		if(conn!=null) {
			try {
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	public static void main(String[] args) throws SQLException {
		DbUtil dbUtil = new DbUtil();
		Connection conn = dbUtil.getConnection();
		System.out.println(conn);
	}
	public static  Connection getConnection() {
		Connection conn = null;
		String url = "jdbc:mysql://localhost:3306/financedb";
		try {
			conn = DriverManager.getConnection(url, "root", "1234");
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return conn;
	}
}